package com.ruoyi.zhjd.laboratory.modules.asphaltSofteningPoint.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.ruoyi.common.core.domain.R;
import com.ruoyi.zhjd.common.util.ZhjdIotUtils;
import com.ruoyi.zhjd.laboratory.modules.asphaltSofteningPoint.entity.AsphaltSofteningPointEntity;
import com.ruoyi.zhjd.laboratory.modules.asphaltSofteningPoint.entity.AsphaltSofteningPointResEntity;
import com.ruoyi.zhjd.laboratory.modules.asphaltSofteningPoint.service.AsphaltSofteningPointService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import java.util.Arrays;
import java.util.Map;

/**
 * 沥青软化点试验仪
 *
 * @author sx
 * @email
 * @date 2023-07-11 18:29:54
 */
@RestController
@RequestMapping("laboratory/asphaltSofteningPoint")
public class AsphaltSofteningPointController {

    @Autowired
    private AsphaltSofteningPointService asphaltSofteningPointService;

    /**
     * 列表
     */
    @RequestMapping("/page")
    //
    public R page(@RequestParam Map<String, Object> params){
        IPage page = asphaltSofteningPointService.queryPage(params);
        return R.ok(page);
    }


    /**
     * 信息
     */
    @RequestMapping("/find/{id}")
    //
    public R find(@PathVariable("id") String id){
		AsphaltSofteningPointEntity asphaltSofteningPoint = asphaltSofteningPointService.getInfo(id);
        return R.ok(asphaltSofteningPoint);
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
    //
    public R save(@RequestBody AsphaltSofteningPointEntity asphaltSofteningPoint){
		asphaltSofteningPointService.saveData(asphaltSofteningPoint);
        return R.ok();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    //
    public R update(@RequestBody AsphaltSofteningPointEntity asphaltSofteningPoint){
        asphaltSofteningPointService.updateData(asphaltSofteningPoint);
        return R.ok();
    }


    /**
     * 删除单个
     */
    @RequestMapping("/delete/{id}")
    //
    public R deleteOne(@PathVariable("id") String id){
        asphaltSofteningPointService.deleteOneData(id);
        return R.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
    //
    public R delete(@RequestBody String[] ids){
        asphaltSofteningPointService.deleteData(Arrays.asList(ids));
        return R.ok();
    }

    /**
     * 解析数据
     * @param deviceId
     * @param req
     * @return
     */
    @PostMapping("/parsingData/{deviceId}")
    public R parsingData(@PathVariable("deviceId") String deviceId, HttpServletRequest req){
        asphaltSofteningPointService.parsingData(ZhjdIotUtils.dataParsing(req),deviceId);
        return R.ok();
    }

    /**
     * 绑定材料
     */
    @RequestMapping("/changeSample")
    //
    public R changeSample(@RequestBody AsphaltSofteningPointResEntity asphaltSofteningPointRes){
        asphaltSofteningPointService.changeSample(asphaltSofteningPointRes);
        return R.ok();
    }
}
